﻿<!DOCTYPE HTML>
<html lang="zh">
<head>
<title>IsLabel - 语法 &amp; 使用 | AutoHotkey v2</title>
<meta name="description" content="The IsLabel function returns a non-zero number if the specified label exists in the script." />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
<script type="text/javascript">$(function(){0<=window.navigator.userAgent.toLowerCase().indexOf("ucbrowser")&&CaoNiMaDeUc()})</script>
</head>
<body>

<h1>IsLabel</h1>

<p>如果脚本中存在指定的标签, 则返回非零数字.</p>

<pre class="Syntax">IsLabel := <span class="func">IsLabel</span>(LabelName)</pre>
<h2 id="Parameters">参数</h2>
<dl>

  <dt>LabelName</dt>
  <dd>
    <p>类型: <a href="../Concepts.htm#strings">字符串</a></p>
    <p><a href="Gosub.htm">子程序</a>, <a href="../Hotkeys.htm">热键</a>或<a href="../Hotstrings.htm">热字串</a>的名称(不含 <em>LabelName</em> 中的冒号).</p>
  </dd>

</dl>

<h2 id="Return_Value">返回值</h2>
<p>类型: <a href="../Concepts.htm#boolean">整数(布尔值)</a></p>
<p>如果指定的标签存在, 函数返回 1(true), 如果不存在, 返回 0(false).</p>

<h2 id="Remarks">备注</h2>
<p>在函数(如 <a href="Gosub.htm">Gosub</a>, <a href="Hotkey.htm">Hotkey</a>, <a href="SetTimer.htm">SetTimer</a> 和 <a href="../objects/Menu.htm#Add">Menu.Add</a>) 中指定动态标签时, 此函数可用于避免运行时错误.</p>

<h2 id="Related">相关</h2>
<p><a href="../misc/Labels.htm">Labels</a></p>
<h2 id="Examples">示例</h2>
<div class="ex" id="ExSubroutine">
<p><a href="#ExSubroutine">#1</a></p>
<pre>if IsLabel("Label")
    MsgBox "Subroutine exists"
else
    MsgBox "Subroutine doesn't exist"

Label:
return</pre>
</div>

<div class="ex" id="ExHotkey">
<p><a href="#ExHotkey">#2</a></p>
<pre>if IsLabel("^#h")
    MsgBox "Hotkey exists"
else
    MsgBox "Hotkey doesn't exist"

^#h::return</pre>
</div>

<div class="ex" id="ExHotstring">
<p><a href="#ExHotstring">#3</a></p>
<pre>if IsLabel("::btw")
    MsgBox "Hotstring exists"
else
    MsgBox "Hotstring doesn't exist"

::btw::by the way</pre>
</div>

</body>
</html>